﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base class for popup controls.
	/// </summary>
	[ParseChildren(false)]
	[PersistChildren(true)]
	[Designer(typeof(ContainerControlDesigner))]
	public abstract class BasePopupControl : BaseComplexControl
	{
		#region PUBLIC
		/// <summary>
		/// Ctor.
		/// </summary>
		public BasePopupControl()
		{
			this.Shown = false;
		}
		#region PROPS
		#region DEF
		/// <summary>
		/// Props.
		/// </summary>
		protected static new Properties _clientProperties = Define(BaseComplexControl._clientProperties,
			new BasePropertyDefinition[] {
				//new PropertyDefinition<bool>("Shown", "W", false),
			});
		/// <summary>
		/// Props.
		/// </summary>
		public override Properties ClientProperties
		{
			get
			{
				return _clientProperties;
			}
		}
		#endregion
		[DefaultValue(false)]
		public override bool Shown
		{
			get
			{
				return base.Shown;
			}
			set
			{
				base.Shown = value;
			}
		}
		///// <summary>
		///// Gets or sets shown status of this popup control.
		///// </summary>
		//[DefaultValue(false)]
		//public bool Shown
		//{
		//  get
		//  {
		//    return GetProperty<bool>("Shown");
		//  }
		//  set
		//  {
		//    ViewState["Shown"] = value;
		//  }
		//}
		#endregion
		#region METHODS
		/// <summary>
		/// Gets client script which shows or hides this control.
		/// </summary>
		/// <param name="visibility"></param>
		/// <returns></returns>
		public string GetShowHideScript(bool visibility)
		{
			string s = string.Format("$('{0}').get_Object().set_Shown({1});",
				this.ClientID, visibility.ToString().ToLower());
			return s;
		}
		#endregion
		#endregion
		#region INTERNAL
		/// <summary>
		/// Registers BasePopupControl.js.
		/// </summary>
		protected internal override void RegisterIncludes(IncludeCollection includes)
		{
			base.RegisterIncludes(includes);
			includes.Add(new ScriptResourceInclude("TA.Turbo.Res.JS.Popup.BasePopupControl.js", typeof(BasePopupControl)));
		}
		/// <summary>
		/// Adds visibility style.
		/// </summary>
		/// <param name="writer"></param>
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			//Style[HtmlTextWriterStyle.Display] = Shown ? "" : "none";
			//if (!this.get_IsDesignMode())
			//{
			//  //writer.AddStyleAttribute(HtmlTextWriterStyle.Visibility, this.Shown ? "visible" : "hidden");
			//}

			base.AddAttributesToRender(writer);
		}
		#endregion
	}
}
